import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DeviceModule } from './modules/device/device.module';
import Config from './config'
import { TypeOrmModule } from '@nestjs/typeorm';
import { MerchantModule } from './modules/merchant/merchant.module';
import { ChargeStrategyModule } from './modules/charge-strategy/charge-strategy.module';
import { DevicePortModule } from './modules/device-port/device-port.module';
import { LoginModule } from './modules/login/login.module';
import { UserModule } from './modules/user/user.module';
import { RedisModule } from './redis/redis.module';
import { XjwtModule } from './xjwt/xjwt.module';
import { UserWalletModule } from './modules/user-wallet/user-wallet.module';
import { RabbitmqModule } from './rabbitmq/rabbitmq.module';
import { ChargeModule } from './modules/charge/charge.module';
import { ChargeOrderModule } from './modules/charge-order/charge-order.module';
import { MqttModule } from './mqtt/mqtt.module';
import { MongooseModule } from '@nestjs/mongoose';
import { RechargeModule } from './modules/recharge/recharge.module';
import { PaymentModule } from './payment/payment.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal : true,
      load : [Config]
    }),
    TypeOrmModule.forRootAsync({
      useFactory: (configService: ConfigService) => configService.get('database'),
      inject: [ConfigService],
    }),
    MongooseModule.forRootAsync({
      useFactory: async (configService: ConfigService) => ({
        ...configService.get('mongodb.options')
      }),
      inject: [ConfigService],
    }),
    
    DeviceModule,
    MerchantModule,
    ChargeStrategyModule,
    DevicePortModule,
    LoginModule,
    UserModule,
    RedisModule,

    XjwtModule,

    UserWalletModule,

    RabbitmqModule,

    ChargeModule,

    ChargeOrderModule,

    MqttModule,

    RechargeModule,

    PaymentModule
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
